package cn.zzu.Etrip.twoday.activity;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.example.administrator.etrip.R;

import java.text.SimpleDateFormat;
import java.util.Date;

import cn.zzu.Etrip.oneday.activity.oneday_database;
import cn.zzu.Etrip.twoday.service.lightAndPrice;

import static android.os.Build.VERSION_CODES.O;

/**
 * Created by ASUS on 2018/5/25.
 */
public class TwoDayPayActivity extends Activity {
    private ImageView imageView;
    private TextView textView;
    private Button buycar, payfor;
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.twoday_pay);
        Bundle bundle = getIntent().getExtras();
        final String price = (String) bundle.get("price");
        imageView = findViewById(R.id.pay_image);
        textView = findViewById(R.id.pay_instruct);
        imageView.setImageResource((Integer) bundle.get("key"));
        textView.setText((String) bundle.get("value"));
        buycar = findViewById(R.id.buy_car);
        payfor = findViewById(R.id.two_pay);
        payfor.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                AlertDialog.Builder pay = new AlertDialog.Builder(TwoDayPayActivity.this);
                pay.setTitle("立即订购");
                pay.setMessage("☆☆☆请确定订购☆☆☆");
                pay.setIcon(R.mipmap.a);
                pay.setNegativeButton("关闭",
                        new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                //当点击不过买时，弹出一窗口
                              Toast.makeText(TwoDayPayActivity.this,"我会等着你哦",Toast.LENGTH_SHORT).show();
                            }
                        });
                pay.setPositiveButton("确定",
                        new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                            AlertDialog.Builder finalResult = new AlertDialog.Builder(TwoDayPayActivity.this);
                                finalResult.setMessage("☺☺☺☺成功☺☺☺☺");
                                finalResult.setPositiveButton("关闭", new DialogInterface.OnClickListener() {
                                    @Override
                                    public void onClick(DialogInterface dialog, int which) {
                                        //立即购买页面****
                                        Intent intent = new Intent(TwoDayPayActivity.this,oneday_database.class);
                                        //这是一个虚拟的数据，日后需要改变的数据*****************************************************************
                                        intent.putExtra("目的地", lightAndPrice.place_name[(int)(Math.random()*15)]);
                                        intent.putExtra("singleprice",Integer.parseInt(price.subSequence(price.indexOf("￥")+1,price.toString().indexOf("元")).toString()));
                                        intent.putExtra("number",1);
                                        startActivity(intent);
                                    }
                                });
                                finalResult.create();
                                finalResult.show();
                            }
                        });
                pay.show();
            }
        });
        buycar.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                AlertDialog.Builder normalDialog =
                        new AlertDialog.Builder(TwoDayPayActivity.this);
                normalDialog.setIcon(R.drawable.ic_launcher_background);
                normalDialog.setTitle("购物车");
                normalDialog.setMessage("已经加入购物车");
                normalDialog.setPositiveButton("确定",
                        new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                Date date = new Date ();
                                SimpleDateFormat format = new SimpleDateFormat("hh:mm:ss");
                               String dateString = format.format(date);
                           Intent intent = new Intent();
                           intent.setAction("android.intent.action.buycar");
                           Bundle bundle = new Bundle();
                           bundle.putString("price",price);
                           bundle.putString("date",dateString);
                           bundle.putInt("radioButton",1);
                           intent.putExtras(bundle);
                           startActivity(intent);
                            }
                        });
                normalDialog.show();
             /*   normalDialog.setNegativeButton("关闭",
                        new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                            }
                        });*/

            }
        });
        ///付款按钮的监听事件

    }
}
